#include "CDTime.h"
#include "UnityCode.h"
#include "CDTimeManager.h"

CCDTime::CCDTime()
{
	m_Id = CDTimeManager::getInstance()->AddTime(this);
	ReSet(); 
	m_Active = true;
	
}
CCDTime::~CCDTime()
{
	CDTimeManager::getInstance()->DeleteTime(this);
}

void	CCDTime::Run()
{

}

bool	CCDTime::IsFinish()
{
	if( ( millisecondNow() - m_LastTime ) > m_Limit )
		return true;
	return false;
}

float	CCDTime::GetPersent( void )
{
	float fPresent = 0.0;


	if( m_Limit > 0 )
	{
		unsigned long destime = (millisecondNow() - m_LastTime);
		fPresent = (float)(destime /m_Limit );
	}
	else
	{
		fPresent = 1.0;	
	}

	

	if( fPresent >= 1 )
		fPresent = 1.0;

	return fPresent;
}

void	CCDTime::ReSet()
{
	m_LastTime =millisecondNow();
	SetLimit(0);
}

void	CCDTime::ReStart()
{
	m_LastTime = millisecondNow();
}
void    CCDTime::SetCanUse( void )
{
	m_LastTime = millisecondNow() - m_Limit;
}

void CCDTime::FixLastPauseTime( unsigned long dt )
{
	m_LastTime += dt;
}


void CCDTime::SetActive( bool bActive )
{
	if(bActive == false)
		m_LastTime = 0;

	m_Active = bActive;
}
